<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //promise then方法
        const promise = new Promise((resolve, reject) => {
            setTimeout(() => {
                const name = "huohua";
                if (true) {
                    resolve(name);
                }
                else {
                    reject("失败");
                }
            }, 2000)
        })
        promise.then(res => {
            let str = `我是${res}的一员`
            return str
        }, err => {
            console.log(err);
        }).then(res => {
            console.log(res);
        })
        //promise async方法
        function fn() {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    console.log("1233");
                    resolve("huohua")
                }, 1000)
            })
        }
        async function myfn() {
            console.log("1");
            let data = await fn();
            console.log(data);
            console.log("2");

        }
        myfn()
    </script>
</body>

</html>